{layout name="layout/food" /}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">添加优惠券</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">名称 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[name]"
                                           value="" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">分类</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" v-model="type" name="data[type]" value="10" data-am-ucheck> 现金券
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" v-model="type" name="data[type]" value="20" data-am-ucheck> 折扣券
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" v-model="type" name="data[type]" value="30" data-am-ucheck> 赠送券
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" v-model="type" name="data[type]" value="40" data-am-ucheck> 减免券
                                    </label>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">类型</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[rule]" value="10" data-am-ucheck checked>
                                        通用券
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[rule]" value="20" data-am-ucheck>
                                        外卖券
                                    </label>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">规则</label>
                                <div v-if="type == 10" class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[mode]" value="1" data-am-ucheck checked>
                                        立减
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[mode]" value="2" data-am-ucheck>
                                        首单减
                                    </label>
                                </div>
                                <div v-if="type == 20" class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[mode]" value="6" data-am-ucheck checked>
                                        等级折扣
                                    </label>
                                </div>
                                <div v-if="type == 30" class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[mode]" value="3" data-am-ucheck checked>
                                        满赠
                                    </label>
                                </div>
                                <div v-if="type == 40" class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[mode]" value="4" data-am-ucheck checked>
                                        满减
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[mode]" value="5" data-am-ucheck>
                                        满折
                                    </label>
                                </div>
                            </div>
                            <div v-if="type == 10" class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">减免金额 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" min="0" class="tpl-form-input" name="data[values][money]"
                                           value="" required>
                                </div>
                            </div>
                            <div v-if="type == 20">
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">等级要求 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[values][lv]" value="0" data-am-ucheck checked>
                                        不限
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[values][lv]" value="1" data-am-ucheck>
                                        V1
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[values][lv]" value="2" data-am-ucheck>
                                        V2
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[values][lv]" value="3" data-am-ucheck>
                                        V3
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[values][lv]" value="4" data-am-ucheck>
                                        V4
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[values][lv]" value="5" data-am-ucheck>
                                        V5
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[values][lv]" value="6" data-am-ucheck>
                                        V6
                                    </label>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">折扣 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" min="1" max="99" class="tpl-form-input" name="data[values][discount]"
                                           value="" required>
                                    <small>设置80为8折，75为7.5折,取值范围1-99</small>
                                </div>
                            </div>
                            </div>
                            <div v-if="type == 30">
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">满足条件</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[values][condition]" value="10" data-am-ucheck checked>
                                        金额
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[values][condition]" value="20" data-am-ucheck>
                                        数量
                                    </label>
                                    <div class="help-block am-margin-top-sm">
                                        <small>金额：满足订单总金额，数量：满足单品订购数量</small>
                                    </div>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">条件数值</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" min="1" class="tpl-form-input" name="data[values][num]"
                                           value="" required>
                                    <small>如条件设置金额，该参数值为满足条件的数值。如条件设置为数量，为单品购买数量值</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">赠品类型</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" v-model="checked" name="data[values][type]" value="10" data-am-ucheck>
                                        优惠券
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" v-model="checked" name="data[values][type]" value="20" data-am-ucheck>
                                        商品
                                    </label>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3  am-u-lg-2 am-form-label form-require"> 选择赠品 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <div v-show="checked == 10" class="widget-become-goods am-form-file am-margin-top-xs">
                                        <button @click="coupon()" type="button"
                                                class="upload-file am-btn am-btn-secondary am-radius">
                                            <i class="am-icon-cloud-upload"></i> 选择优惠券
                                        </button>
                                        <div class="coupon-list uploader-list am-cf">
                                        </div>
                                    </div>
                                    <div v-show="checked == 20" class="widget-become-goods am-form-file am-margin-top-xs">
                                        <button @click="goods()" type="button"
                                                class="upload-file am-btn am-btn-secondary am-radius">
                                            <i class="am-icon-cloud-upload"></i> 选择商品
                                        </button>
                                        <div class="goods-list uploader-list am-cf">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            </div>
                            <div v-if="type == 40">
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">条件</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[values][condition]" value="10" data-am-ucheck checked>
                                        金额
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[values][condition]" value="20" data-am-ucheck>
                                        数量
                                    </label>
                                    <div class="help-block am-margin-top-sm">
                                        <small>金额：按照金额计算，数量：按照单品订购数量</small>
                                    </div>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">满足数值（金额/数量）</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" min="1" class="tpl-form-input" name="data[values][num]"
                                           value="" required>
                                    <small>如条件设置金额，为订单金额。如条件设置为数量，为单品购买数量值</small>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">减/折数值 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" min="0" class="tpl-form-input" name="data[values][money]"
                                           value="" required>
                                    <small>上述如设置为金额，为减免的金额，如设置为折扣，则为折扣率，折扣设置80为8折，设置为75则为7.5折</small>
                                </div>
                            </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">有效期限</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[valid_time]" value="10" data-am-ucheck>
                                        当天
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[valid_time]" value="20" data-am-ucheck>
                                        一周
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[valid_time]" value="30" data-am-ucheck checked>
                                        一月
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[valid_time]" value="40" data-am-ucheck>
                                        一年
                                    </label>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">规则说明 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[explain]"
                                           value="" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">显示样式</label>
                                <div class="am-u-sm-9 am-u-end">
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[color]" value="warning" data-am-ucheck checked> 橙色
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[color]" value="success" data-am-ucheck> 绿色
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[color]" value="primary" data-am-ucheck> 蓝色
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[color]" value="error" data-am-ucheck> 红色
                                    </label>
                                    <label class="am-radio-inline">
                                        <input type="radio" name="data[color]" value="info" data-am-ucheck> 灰色
                                    </label>
                                </div>
                            </div>
                            <!-- 表单提交按钮 -->
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <button type="submit" class="j-submit am-btn am-btn-secondary">提交
                                    </button>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{include file="food/market/coupon/tpl_gift" /}
<script src="/assets/plugins/vue/vue.min.js"></script>
<script src="/addons/food/js/select.data.js"></script>
<script>
    // 渲染页面
    new Vue({
        el: '#my-form',
        data: {
            type: 10,
            checked: 10
        },
        methods:{
            goods(){
                var $userList = $('.goods-list');
                $.selectData({
                    title: '选择商品',
                    uri: 'goods/lists',
                    dataIndex: 'goods_id',
                    done: function (data) {
                        var goods = [data[0]];
                        $userList.html(template('tpl-goods-item', goods));
                    }
                });
            },
            coupon(){
                var $userList = $('.coupon-list');
                $.selectData({
                    title: '选择优惠券',
                    uri: 'coupon/lists',
                    dataIndex: 'coupon_id',
                    done: function (data) {
                        var coupon = [data[0]];
                        $userList.html(template('tpl-coupon-item', coupon));
                    }
                });
            }
        }
    });
    $(function () {
        /**
         * 表单验证提交
         */
        $('#my-form').formPost();

    });
</script>
